package com.itheima.controller;

import com.itheima.pojo.User;
import com.itheima.service.ConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * <dl>
 * <dd>描述: ~节点业务逻辑实现</dd>
 * <dd>创建时间：  11:45 2020/7/17</dd>
 * <dd>创建人： zz</dd>
 * <dt>版本历史: </dt>
 * <pre>
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2020/7/17      guodong       1.0        1.0 Version
 * </pre>
 * </dl>
 */

@RestController
@RequestMapping("consumer")
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private ConsumerService consumerService;
    @Value("${server.port}")
    private String port;


    /**
    * @Date: 11:48 2020/7/17
    * @Param: [id]
    * @return: com.itheima.pojo.User
    * @NewDescription: 根据id查询用户
    **/
    @GetMapping("findUserById/{id}")
    public User findUserById(@PathVariable("id")Integer id){

        /*方式三：
            使用ribbon

         */
  /*      String url = "http://user-service/user/findUserById/" + id;
        User user = restTemplate.getForObject(url, User.class);
*/
        User user = consumerService.findUserById(id);
        user.setNote(user.getNote() + " 消费者端口号：" + port);
        return user;
    }


}
